$(function () {
                //搜索栏 ↓
            $('.search_txt').focus(function (){
                $(this).val('');
            })
                //搜索栏 ↑
                
            $(".rule a").click(function () {
                $(this).addClass('hover').siblings('a').removeClass('hover');
                var av_id = [];
                $("a.spec.hover").each(function (i) {
                    av_id.push($(this).attr("av_id"));
                })
                var st_id = $("input[name='st_id']").val();
                $.post("Index&m=getStockId", {st_id: st_id, av_id: av_id}, function (st_id) {
                    if (st_id == 0) {
                        $(".kc strong']").addClass("warning").text("库存不足");
                    } else {
                        var url =  WEB+"/Index/goods/st_id/"+st_id + ".html";
                        location.href = url;
                    }
                })
            })
        })
        //更改商品购买数量
        $(function () {
            $("input[name='gcount']").blur(function () {
                //购买数量
                var count = Math.max(parseInt($(this).val()), 1);
                //当前商品的总库存数
                var stock = parseInt($("#stock").text());
                gcount = Math.min(count, stock);
                $(this).val(gcount)
                updateCartUrl();//修改添加到购物车的链接url
            })
        })
        //修改购物车链接
        function updateCartUrl() {
            var st_id = $("input[name='st_id']").val();//库存商品st_id
            var count = $("input[name='gcount']").val();//购买数量
            var url = WEB+"/shoppingCar/add&st_id=" + st_id + "&gcount=" + count;
            $("a.inCar").attr("href", url);
        }